package com.teyao.teyao_back.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.teyao.teyao_back.entity.Driver;
import com.teyao.teyao_back.entity.ResponseMessage;
import com.teyao.teyao_back.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/driver")
public class DriverController {
    @Autowired
    private DriverService driverService;

    @GetMapping("/selectAll")
    public ResponseMessage selectAll() {
        return driverService.selectAll();
    }

    @GetMapping("/selectByUserId")
    public ResponseMessage selectByUserId(Integer userId) {
        QueryWrapper<Driver> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setData(driverService.getOne(queryWrapper));
        return responseMessage;
    }

}
